# -*- coding: utf-8 -*-

from nltk.corpus import udhr
import nltk, re, pprint
import re
import codecs
from nltk.corpus import BracketParseCorpusReader

class quran:
    def read_quran(self):
        path = ('D:\\quran\quranic-corpus-text-0.1.txt')
        #--------------------- read file with unicode utf-8 ----------------------------
        fil = codecs.open(path, encoding='utf-8')
        # containe all raws
        out = fil.readlines()
        #print "file read complete"
        #--------------------- core of quran list is output ----------------------------
        # remove comments lines
        output=out[58:]
        return output

    #----------------- this method return list of 2 dimantion ----------------------
    # first dimention is no of raw
    # second dimention is column with Format: <chapter> | <verse> | <word> | <token> | <part-of-speech>
    # lists represent raws

    def getlist(self,lists):
        quranlist=[]
        for i in lists:
            string=''
            for x in i:
               string=string+x

            st=string.split("|")
            quranlist.append(st)
        return quranlist

    #===============================================================================
    # will print line 5 , get word from it
    #print l[5][3]
    #------------------------------ search for word --------------------------------

    # input is list 2 dimention
    # string which you search for BUT with taskeel

    def searchOfWord(self,lists,string):
        ayat=[]
        y=len(lists)
        for i in range(0,y):
            if lists[i][3]== string:
                # s represent sura , a aya
                s=lists[i][0]
                a=lists[i][1]
                d=[s,a]
                # will match all ayat found
                ayat.append(d)
        
        return ayat
#------------------------------Return array of ayat in sura , no of aya ------------------------------------
# Also can input suran , aya to print whole aya
# First list is quran rows
# second can get search output or enter sura , aya
# can print aya from sura , aya number
# l may represent many sura
    def getayat(self,lists,l):
        x=len(l)
        y=len(lists)
        aya=[]
        # if we search for aya , sura
        # i [0] == sura , i[1] = aya

        for i in range(0,x):
            # j represent ayat of whole quran
            aya1='\n\nSura -> '+l[i][0]+' , Ayaa -> '+l[i][1]+'\n\n'
            
            for j in range(0,y):
                # 0 mean sura number
                if (lists[j][0]== l[i][0])&(lists[j][1]==l[i][1]):
                    # when match get all ayat until reach end of aya
                    aya1=aya1+lists[j][3]+' '
                    #print l[i][0],"====",l[i][1]


            #aya=aya+aya1+'\n\n'
            aya.append(aya1)

        return aya
    #------------------------------ get numOfaya ------------------------------------
    # lists = quran raws
    # x represent sura number
    # a represnt ayat number
    def numOfaya(self,lists,x):
        y=len(lists)
        for i in range(0,y):
            if lists[i][0] == x:
                a=l[i][1]
        return a
     #------------------ get numOfaya for all sura(s) ----------------
    def numOfayat(self,lists):
        result=[]

        for i in range(1,115):
            a=numOfaya(lists,unicode(i))
            result.append(a)
        return result
    #---------------- smallest sura ---------------------
    #get smallest sura
    def smallest(self,lists):
        smallest=int(lists[0])
        result=[1,smallest]
        for i in range(1,len(lists)):
            small=int(lists[i])
            if small < result[1]:
                result=[i,small]
        return result

    #------------------------------------------------------------
    #out = read_quran('')
    
